﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Katamino.Logic
{
    public class BitTransposer
    {
        private UInt64[] _cache;
        private int _w;

        public BitTransposer(int width)
        {
            _w = width;
            _cache = new UInt64[32];
        }

        public UInt64 Transpose (UInt64 _v)
        {
            if (_v == 0) return (UInt64)0;

            if (_cache[_v] > (UInt64)0) return _cache[_v];

            UInt64 result = (_v & (UInt64)1) + (Transpose(_v >> 1) << _w);

            _cache[_v] = result;

            return result;
        }
    }
}
